﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 排序
{
    public  class Sorts
    {
        public static int [] SingleBubbleSort(int [] nums )
        {
            for (int i = 0; i < nums.Length; i++)
            {
                for (int j = 0; j < nums.Length-i-1; j++)
                {
                    if (nums[j] > nums[j + 1])
                    {
                        var temp = nums[j];
                        nums[j] = nums[j+1];
                        nums[j + 1] = temp;
                    }
                }
            }
            return nums;
        }
        public static int [] BubbleSort(int [] nums )
        {
            int low = 0;
            int high = nums.Length - 1;
            while (low < high)
            {
                for (int i = low; i < high; i++)
                {
                    if (nums[i] > nums[i + 1])
                    {
                        var temp = nums[i];
                        nums[i] = nums[i + 1];
                        nums[i + 1] = temp;
                    }
                }
                high--;
                for (int i = high; i > low; i--)
                {
                    if (nums[i] < nums[i - 1])
                    {
                        var temp = nums[i];
                        nums[i] = nums[i -1];
                        nums[i - 1] = temp;
                    }
                }
                low++;
            }
            return nums;
        }
    }
}
